import utils from "@/utils";

const { request } = utils;
const login = (loginData) => {
  const params = new URLSearchParams();
  for (let key in loginData) {
    params.append(key, loginData[key]);
  }
  return request.post("/user/login", params, {
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
};

const register = (regData) => {
  const params = new URLSearchParams();
  for (let key in regData) {
    params.append(key, regData[key]);
  }
  return request.post("/user/register", params, {
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
};

const getUserInfo = (username) => {
  return request.get(`/user/userInfo/${username}`);
};

export { login, register, getUserInfo };
